$(function () {
    let ws;
    if("WebSocket" in window) {
        // 获取招聘者id
        let clientID = $("#eid").val();
        // 创建WebSocket对象,需要注意请求路径
        ws = new WebSocket("ws://127.0.0.1:8081/hire/web/" + clientID);
        // 接收到服务端消息时触发
        ws.onmessage = function (evt) {
            let received_msg = evt.data;
            layer.msg(received_msg,{
                offset: '50px'
            });
            layui.use("table",function () {
                let table = layui.table;
                table.reload('resume', {
                    ulr: '/hire/employer/resume/data?status=未处理'
                });
            })
        };
    }
});
layui.use(["table", "form"], function () {
    let form = layui.form;
    let table = layui.table;
    table.render({
        elem: '#resume',
        title: '未处理简历',
        url: "/hire/employer/resume/data?status=未处理",
        response: {
            statusName: 'code',
            statusCode: 200,
            msgName: 'msg',
            count: 'count',
            dataName: 'data'
        },
        height: "600px",
        page: true,
        limit: 10,
        limits: [2, 5, 10, 20],
        cols: [[
            {type: 'checkbox', fixed: 'left'},
            {title: '序号', templet: '#xuhao', width: 80, align: 'center'},
            {
                field: 'recruitment_id', title: '职位id', hide: true, templet: function (res) {
                    return res.recruitment.id;
                }
            },
            {
                field: 'resume_id', title: '简历id', hide: true, templet: function (res) {
                    return res.resume.id;
                }
            },
            {
                field: 'delivery_id', title: '简历投递id', hide: true, templet: function (res) {
                    return res.delivery.id;
                }
            },
            {
                field: 'name', title: '姓名', width: 80, templet: function (res) {
                    return res.resume.name;
                }
            },
            {
                field: 'sex', title: '性别', width: 60, templet: function (res) {
                    return res.resume.sex;
                }
            },
            {
                field: 'identity', title: '身份', width: 80, templet: function (res) {
                    return res.resume.resIdentity;
                }
            },
            {
                field: 'salary', title: '薪资要求', templet: function (res) {
                    return res.resume.salaryRequirement;
                }
            },
            {
                field: 'state', title: '状态', width: 60, templet: function (res) {
                    return res.resume.resState;
                }
            },
            {
                field: 'delivery_recruitment', title: '投递职位', width: 200, templet: function (res) {
                    return res.recruitment.name;
                }
            },
            {
                field: 'delivery_time', title: '投递时间', width: 180, templet: function (res) {
                    return res.delivery.deliveryTime;
                }
            },
            {field: 'relationName', toolbar: '#barDemo', title: '操作', width: 400}
        ]],
        text: {none: '您暂时没有未处理的投递简历'}
    });
    form.on('select(selectTime1)', function(data){
        let v = data.value;
        table.reload('resume',{
            where:{getDay:v}
        });
    });
    table.on('tool(resume)', function (obj) {
        // let getDay = f.data.value;
        // alert(getDay);
        let resumeId = obj.data.resume.id;
        let deliveryId = obj.data.delivery.id;
        if (obj.event == 'view') {
            alert("view");
            $.post('/hire/employer/resume/view', {id: resumeId}, function (res) {
                if (res.code == '200') {
                    alert("成功");
                    window.open('/hire/resume/resume_preview?resumeId=' + resumeId);
                } else {
                    layer.msg("很抱歉,请重试");
                }
            });
        } else if (obj.event == 'yes') {
            $.post('/hire/employer/resume/update/status', {id: deliveryId, status: '有意向'}, function (res) {
                if (res.code == '200') {
                    layer.msg("已设为有意向", {icon: 6});
                    obj.del();
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            });
        } else if (obj.event == 'no') {
            $.post('/hire/employer/resume/update/status', {id: deliveryId, status: '无意向'}, function (res) {
                if (res.code == '200') {
                    layer.msg("已设为无意向", {icon: 5});
                    obj.del();
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            })
        } else if (obj.event == 'black') {
            layer.confirm('请确认是否取屏蔽该用户', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.post('/hire/employer/add/blacklist', {resumeId: resumeId}, function (res) {
                    if (res.code == '200') {
                        layer.msg("屏蔽成功", {icon: 1})
                    } else if (res.code == '500') {
                        layer.msg(res.msg, {icon: 2})
                    } else {
                        layer.msg(res.msg, {icon: 0})
                    }
                })
            });
}
});
});